Created
January 10, 2020 18:08
-
-
Save sumitkharche/3cb814f456d42ba722a2165e45163827 to your computer and use it in GitHub Desktop.
AutoMapperProfile.cs with conditional mappings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using AutoMapper; | |
namespace automapper_sample | |
{ | |
public class AutoMapperProfile : Profile | |
{ | |
public AutoMapperProfile() | |
{ | |
CreateMap<StudentDTO, Student>() | |
.ForMember(dest => dest.City, opt => opt.MapFrom(src => src.CurrentCity)) | |
.ForMember(dest => dest.IsAdult, opt => opt.MapFrom(src => src.Age > 18 ? true : false)); | |
CreateMap<AddressDTO, Address>(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment